home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / start / code.lua next >
Encoding:
Text File  |  2005-07-16  |  10.1 KB  |  278 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. -- Init
  4. -- -----------------------------------------------------------------
  5. local function prog_init()
  6.     initModels()
  7.     sound_playMusic("music/rybky04.ogg")
  8.     local pokus = getRestartCount()
  9.  
  10.  
  11.     -- -------------------------------------------------------------
  12.     local function prog_init_room()
  13.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  14.         local boring = 0
  15.  
  16.         room.uzreklnavod = 0
  17.         room.qcount = 0
  18.         if pokus == 1 then
  19.             room.qnavod1 = 110
  20.             room.qnavod2 = 500
  21.         else
  22.             room.qnavod1 = 400
  23.             room.qnavod2 = 2000
  24.         end
  25.         room.kecyoceli = random(100) + 80
  26.         room.malanepohne = 0
  27.         room.malanemuze = 0
  28.         room.tlustoch = 0
  29.         room.restrt = 0
  30.  
  31.         return function()
  32.             if small:getAction() == "rest" and big:getAction() == "rest" then
  33.                 boring = boring + 1
  34.             else
  35.                 boring = 0
  36.             end
  37.  
  38.             room.qcount = room.qcount + 1
  39.             if room.qcount == 3 then
  40.                 addm(15 + random(5), "1st-m-cotobylo")
  41.                 addv(6, "1st-v-netusim")
  42.                 addv(random(10) + 10, "1st-v-ven")
  43.                 addm(3, "1st-m-pockej")
  44.             end
  45.             if no_dialog() and trubka.cinnost == 0 and isReady(small) and isReady(big) then
  46.                 if room.qnavod1 > 0 and boring >= room.qnavod1 then
  47.                     room.qnavod1 = -1
  48.                     addm(5, "1st-m-proc")
  49.                     planBusy(small, true, 3)
  50.                     addm(5, "1st-m-hej")
  51.                 elseif game_getCycles() >= room.qnavod2 and room.qnavod2 ~= -1 then
  52.                     room.qnavod1 = -1
  53.                     planBusy(small, true, 3)
  54.                     addm(5, "1st-m-hej")
  55.                 end
  56.                 if room.qnavod1 == -1 then
  57.                     room.qnavod1 = 600
  58.                     room.qnavod2 = -1
  59.                     planBusy(big, true, 4)
  60.                     addv(5, "1st-v-navod1")
  61.                     planBusy(small, false, 3)
  62.                     planBusy(big, false, 1)
  63.                     planBusy(small, true, 100)
  64.                     planBusy(big, true, 2)
  65.                     addm(3, "1st-m-navod4")
  66.                     addv(0, "1st-v-navod5")
  67.                     addm(2, "1st-m-navod6")
  68.                     planBusy(big, false, 3)
  69.                     planBusy(small, false, 2)
  70.                     addv(20, "1st-v-navod7")
  71.                     addm(20, "1st-m-navod8")
  72.                     if room.uzreklnavod == 0 then
  73.                         room.uzreklnavod = 1
  74.                         addv(35, "1st-v-davej")
  75.                         addm(0, "1st-m-nechtoho")
  76.                         addv(5, "1st-v-takdobre")
  77.                     end
  78.                 end
  79.                 if room.kecyoceli == 0 then
  80.                     room.kecyoceli = random(600) + 300
  81.                     trubka.cinnost = 1
  82.                 else
  83.                     room.kecyoceli = room.kecyoceli - 1
  84.                 end
  85.                 if room.malanemuze == 0 and trubka.pohnul == 0 and small.X == 13 then
  86.                     room.malanemuze = 1
  87.                     addm(random(5) + 2, "1st-m-neprojedu")
  88.                 end
  89.                 if room.malanepohne == 0 and trubka.pohnul == 0 and small.X == 12 and small.Y >= 10 then
  90.                     room.malanepohne = 1
  91.                     addm(0, "1st-m-nepohnu")
  92.                 end
  93.                 if room.malanepohne > 0 then
  94.                     room.malanepohne = room.malanepohne + 1
  95.                     if trubka.dir == dir_left then
  96.                         if room.malanepohne < 50 then
  97.                             addv(0, "1st-v-takukaz")
  98.                         end
  99.                         room.malanepohne = -1
  100.                     end
  101.                 end
  102.                 if room.malanepohne ~= -2 and trubka.dir == dir_left then
  103.                     addm(4, "1st-m-hmmm")
  104.                     room.malanepohne = -2
  105.                 end
  106.                 if zidlev.X >= 20 and big.X >= 21 and big.Y == 15 then
  107.                     switch(room.tlustoch){
  108.                         [0] = function()
  109.                             addv(10, "1st-v-nemuzu")
  110.                             if random(100) < 50 then
  111.                                 addv(4, "1st-v-pribral")
  112.                             end
  113.                             room.tlustoch = room.tlustoch + 1
  114.                         end,
  115.                         [2] = function()
  116.                             addv(10, "1st-v-posunout")
  117.                             room.tlustoch = room.tlustoch + 1
  118.                         end,
  119.                     }
  120.                 end
  121.                 if big.X < 20 and room.tlustoch == 1 then
  122.                     room.tlustoch = room.tlustoch + 1
  123.                 end
  124.                 if room.restrt == 0 and trubka.X <= 9 and small.X <= trubka.X - 3 then
  125.                     planBusy(small, false)
  126.                     addm(10, "1st-m-pokud")
  127.                     planBusy(big, true, 3)
  128.                     addv(3, "1st-v-znovu")
  129.                     if random(100) < 50 then
  130.                         addm(0, "1st-m-backspace")
  131.                         addv(0, "1st-v-jedno")
  132.                     end
  133.                     planBusy(small, false, 3)
  134.                     addv(5, "1st-v-najit")
  135.                     planBusy(big, false)
  136.                     room.restrt = 1
  137.                 end
  138.             end
  139.             if no_dialog() and room.restrt == 0 and small:isOut() and isReady(big) and big.X <= 23 and zidlev.X >= 20 then
  140.                 addv(30, "1st-v-chyba")
  141.                 planBusy(big, true)
  142.                 addv(10, "1st-v-nedostanu")
  143.                 planBusy(big, false)
  144.                 planBusy(big, true, 50)
  145.                 addv(3, "1st-v-stiskni")
  146.                 if random(100) < 50 then
  147.                     addm(0, "1st-m-backspace")
  148.                     addv(0, "1st-v-jedno")
  149.                 end
  150.                 --[[ TODO: control panel
  151.                 addv(5, "1st-v-najit")
  152.                 ]]
  153.                 planBusy(big, false)
  154.                 room.restrt = 1
  155.             end
  156.         end
  157.     end
  158.  
  159.     -- -------------------------------------------------------------
  160.     local function prog_init_trubka()
  161.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  162.  
  163.         trubka.cinnost = 0
  164.         trubka.pohnul = 0
  165.  
  166.         return function()
  167.             if trubka.dir == dir_left or trubka.dir == dir_right then
  168.                 trubka.pohnul = 1
  169.             end
  170.             local anim_table = {
  171.                 [1] = function()
  172.                     trubka.cinnost = trubka.cinnost + 1
  173.                     trubka.afaze = trubka.afaze + 1
  174.                     trubka.delay = 7
  175.                 end,
  176.                 [5] = function()
  177.                     if trubka.delay > 0 then
  178.                         trubka.delay = trubka.delay - 1
  179.                     else
  180.                         trubka.cinnost = trubka.cinnost + 1
  181.                     end
  182.                 end,
  183.                 [6] = function()
  184.                     trubka.afaze = 5
  185.                     trubka.cinnost = trubka.cinnost + 1
  186.                     trubka.delay = 8
  187.                 end,
  188.                 [7] = function()
  189.                     if trubka.delay > 0 then
  190.                         if random(100) < 10 then
  191.                             trubka.afaze = 4
  192.                         else
  193.                             trubka.afaze = 5
  194.                         end
  195.                         trubka.delay = trubka.delay - 1
  196.                     else
  197.                         trubka.cinnost = trubka.cinnost + 1
  198.                     end
  199.                 end,
  200.                 [8] = function()
  201.                     trubka:planDialog(0, "1st-x-ocel")
  202.                     trubka.cinnost = trubka.cinnost + 1
  203.                 end,
  204.                 [9] = function()
  205.                     if trubka:isTalking() then
  206.                         if trubka.afaze == 4 then
  207.                             trubka.afaze = 5
  208.                         end
  209.                         if math.mod(game_getCycles(), 3) == 1 then
  210.                             if random(2) == 0 then
  211.                                 trubka.afaze = trubka.afaze + 1
  212.                             else
  213.                                 trubka.afaze = trubka.afaze - 1
  214.                             end
  215.                             if trubka.afaze == 4 then
  216.                                 trubka.afaze = 8
  217.                             elseif trubka.afaze == 9 then
  218.                                 trubka.afaze = 5
  219.                             end
  220.                         end
  221.                         if trubka.afaze == 5 and random(100) < 40 then
  222.                             trubka.afaze = 4
  223.                         end
  224.                     else
  225.                         trubka.cinnost = trubka.cinnost + 1
  226.                     end
  227.                 end,
  228.                 [10] = function()
  229.                     trubka.afaze = 5
  230.                     trubka.cinnost = trubka.cinnost + 1
  231.                 end,
  232.                 [11] = function()
  233.                     trubka.afaze = trubka.afaze - 1
  234.                     trubka.cinnost = trubka.cinnost + 1
  235.                 end,
  236.                 [16] = function()
  237.                     trubka.cinnost = 0
  238.                 end,
  239.             }
  240.  
  241.             anim_table[2] = anim_table[1]
  242.             anim_table[3] = anim_table[1]
  243.             anim_table[4] = anim_table[1]
  244.             anim_table[12] = anim_table[11]
  245.             anim_table[13] = anim_table[11]
  246.             anim_table[14] = anim_table[11]
  247.             anim_table[15] = anim_table[11]
  248.             switch(trubka.cinnost)(anim_table)
  249.             trubka:updateAnim()
  250.         end
  251.     end
  252.  
  253.     -- --------------------
  254.     local update_table = {}
  255.     local subinit
  256.     subinit = prog_init_room()
  257.     if subinit then
  258.         table.insert(update_table, subinit)
  259.     end
  260.     subinit = prog_init_trubka()
  261.     if subinit then
  262.         table.insert(update_table, subinit)
  263.     end
  264.     return update_table
  265. end
  266. local update_table = prog_init()
  267.  
  268.  
  269. -- -----------------------------------------------------------------
  270. -- Update
  271. -- -----------------------------------------------------------------
  272. function prog_update()
  273.     for key, subupdate in pairs(update_table) do
  274.         subupdate()
  275.     end
  276. end
  277.  
  278.